package StudyCode.summary.myfile;

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileOwnerAttributeView;
import java.nio.file.attribute.UserPrincipal;
import java.nio.file.attribute.UserPrincipalLookupService;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ManagingFileOwnership {
	public static void main(String[] args) throws Exception {
		Path path = Paths.get("E:\\迅雷下载", "test1.txt");
		FileOwnerAttributeView view = Files.getFileAttributeView(path,
				FileOwnerAttributeView.class);
		UserPrincipalLookupService lookupService = FileSystems.getDefault()
				.getUserPrincipalLookupService();
		UserPrincipal userPrincipal = lookupService.lookupPrincipalByName("tah1986.com");

		view.setOwner(userPrincipal);
		System.out.println("Owner: " + view.getOwner().getName());
	}
}
